package com.lazy.mongo.tutor;

import java.util.Arrays;

import org.bson.*;
import org.bson.codecs.configuration.CodecRegistry;
import org.junit.Test;

import com.mongodb.MongoClient;

public class DocumentDemo {

//    { 
//        "a" : "MongoDB", 
//        "b" : [ 1, 2 ] 
//    }
    @Test
    public void toBsonDocument() {
        BsonDocument doc = new BsonDocument().append("a", new BsonString("MongoDB"))
            .append("b", new BsonArray(Arrays.asList(new BsonInt32(1), new BsonInt32(2))));
        log(doc.toString());
    }
    
    @Test
    public void toDocument() {
        Document doc = new Document().append("a", "MongoDB")
            .append("b", Arrays.asList(1,2));
        log(doc.toString());
        CodecRegistry codecRegistry = MongoClient.getDefaultCodecRegistry();
        log(doc.toBsonDocument(BsonDocument.class, codecRegistry).toString());
    }
    
    private void log(String msg) {
        System.out.println(msg);
    }
}
